
import ronin.graphics.GrimaceGamelet;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import ronin.actor2d.*;
import ronin.util.MessageDispatcher;
import ronin.util.Telegram;
import ronin.scene.QuadScene;
import ronin.ai.State;
import java.util.Vector;
import java.awt.event.*;
import java.awt.*;
import ronin.graphics.Vector2D;
import java.applet.Applet;
import ronin.graphics.RunAppletStub;
import ronin.util.EntityManager;
import java.awt.MouseInfo;
import java.awt.geom.Point2D;

class AITest1 extends GrimaceGamelet {
	
	QuadScene scene;
	Rectangle2D screenSize = new Rectangle2D.Double(0.0, 0.0, 800.0, 400.0);
	
	
	
	public static final int MSG_NEW_WAYPOINT = 0;
	
	SmartStaticActor actor;
	StaticActorGroup actorGroup;
	
	AITest1(){
		super(800, 400, true);
	}
	
	
	public void setupGame() {
		scene = new QuadScene(this, 3, screenSize, screenSize, false);
		actorGroup = new StaticActorGroup("bot.jpg");
		actorGroup.init(this);
		actor = new SmartStaticActor(actorGroup);
		registerEntity(actor);
		actor.setPos(100, 100);
		actor.setVel(1, 1);
		actor.setGlobalState(new TestGlobalState(actor));
		actor.update();
		scene.add(actor);
		gameletStarted = true;
	}
	
	
	public void runGame() {
	//	processPlayerInput();
	
		Vector2D mousepoint;
		Point p = MouseInfo.getPointerInfo().getLocation();
		out(p.toString());
		mousepoint = new Vector2D.Double(p.x, p.y);
		actor.addToPath(mousepoint);
		
		out("Calling RunGame");
		scene.update();
	}
	
	
	public void processPlayerInput(){
		if(mouseClicked){
			if(button1Pressed){
				// create a waypoint
				Vector wayPoints = new Vector();
				Vector2D wp = new Vector2D.Double();
				wp.makeEqualTo(mousePoint);
				wayPoints.add(wp);
				
				// send new waypoint message
				MessageDispatcher.getInstance().newMessage(0.0, 6, 0, MSG_NEW_WAYPOINT, wayPoints);
			}
		}
	}
	
	public void paintScene(Graphics2D g) {
		runGame();
		scene.paint(g);
	}
	
	
	 public static void main(String args[]) {	
	    String appletName = "AI Test One";
		Frame appletFrame = new Frame(appletName);
		
		WindowListener l = new WindowAdapter() {
		    public void windowClosing(WindowEvent e) {
			System.exit(0);
		    }
		};
		appletFrame.addWindowListener(l);
		appletFrame.setLayout(new GridLayout(1, 0));
		appletFrame.setSize(300, 300);
		appletFrame.show();
		
		
		Applet myApplet = new AITest1();
		// Add the applet to the frame
		appletFrame.add(myApplet);
		
		// Now try to get an applet stub for this class.
		RunAppletStub stub = new RunAppletStub(appletFrame, myApplet,
			"RoNinEnGine " + appletName, "/D:/Users/R/Desktop/RoninEngine/bin/");
		myApplet.setStub(stub);
		// Initialize and start the applet
		myApplet.init();
		myApplet.start();
    }
}

